<template>
	<view class="" style="height: 100%;">
		<!-- <mescroll-uni :fixed="false" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
			:up="upOption" @up="upCallback" @emptyclick="emptyClick"> -->
		<view class="rules">
			<uni-collapse class="" v-model="accordionVal" accordion>
				<view class="rules-item mescroll-item" v-for="(item,index) in goods">
					<uni-collapse-item :show-animation="true" :title-border="none" :border="false">
						<template v-slot:title>
							<view class="rules-item-title title ">
								{{formattedDate(item.days)}}收益
							</view>

						</template>
						<view class="rules-content">
							<view class="bottom-left">
								<view class="bottom-item">
									<view class="bottom-number title">{{number.parsePrice(item.trxAmt)}}</view>
									<view class="bottom-title">交易量（元）</view>

								</view>

								<view class="border"></view>
							</view>
							<view class="bottom-left">
								<view class="bottom-item">

									<view class="bottom-number syAmt title">{{number.parsePrice(item.syAmt)}}</view>
									<view class="bottom-title">收益（元）</view>
								</view>

							</view>

						</view>
					</uni-collapse-item>
				</view>
			</uni-collapse>
		</view>
		<!-- </mescroll-uni> -->
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	const api = require('../../config/api');
	const util = require('../../utils/util');
	import number from '../../utils/number.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				accordionVal: '0',
				number: number, //声明number属性并赋值为引入的number模块
				downOption: {
					auto: true //  false 不自动加载 (mixin已处理第一个tab触发downCallback)  true
				},
				upOption: {
					auto: false, // 不自动加载
					noMoreSize: 4,
					textLoading: '加载中 ...', // 加载中的提示文本
					textNoMore: '暂无更多', // 没有更多数据的提示文本
					empty: {
						tip: '暂无相关数据', // 提示
					},
				},
				goods: [],
				id: '',
				itemStyle: {
					"background-color": '#fff',

					"margin": "5px 15px 0px 15px",
					"padding": "10px",
					"font-size": "14px",
					"border-radius": "10px",
				}
			}
		},
		onLoad(o) {
			this.id = o.id
		},
		onShow() {
			this.getbonusIndex();
		},
		methods: {
			async getbonusIndex() {
				const res = util.request(
					api.skUrl, {
						endTime: '',
						limit: 10,
						page: 1,
						startTime: '',
						type: '2',
						userId: this.id,

					},
					'POST'
				).then(res => {
					
					const newArray = res.data.records.slice(1);

					this.goods = newArray
					
				}).catch(() => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			

			},
			formattedDate(str) {
				const [year, month] = str.split("-");
				return `${year}年${parseInt(month, 10)}月`;
			},

			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				// this.mescroll.endErr();
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				const res = util.request(
					api.skUrl, {
						endTime: '',
						limit: 10,
						page: 1,
						startTime: '',
						type: '2',
						userId: this.id,

					},
					'POST'
				).then(res => {
					// console.log(res);
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					let totalPage = res.data.pages;
					this.mescroll.endByPage(res.data.records.length, totalPage); //必传参数(当前页的数据个数, 总页数)
					//设置列表数据
					if (page.num == 1) this.goods = []; //如果是第一页需手动制空列表
					this.goods = this.goods.concat(res.data.records); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			}
		}
	}
</script>

<style>
	page {
		height: 100%;
		background-color: #F4F4F4;
	}

	.mescroll-upwarp {
		min-height: 0rpx !important;
	}

	.uni-collapse {
		background-color: transparent !important;


	}
</style>
<style lang="scss" scoped>
	.rules {
		// margin: 5px 15px 0px 15px;
		// padding: 10px;
		// font-size: 14px;
		// border-radius: 10px;
	}

	.mescroll-item {
		background-color: #fff;
		// width: 100%;
		// margin: 5px 0;
		margin: 5px 15px 0px 15px;
		padding: 10px;
		font-size: 14px;
		border-radius: 10px;
	}

	.mescroll-item-text {
		display: flex;
		align-items: center;
		justify-content: space-between;

	}

	.title {
		font-size: 16px;
		color: #000;
	}

	.amt {
		font-size: 18px;
		color: #000;
	}

	.mescroll-item-time {
		margin-top: 5px;
		color: #929292;
	}

	.rules-item-title {
		margin-bottom: 20rpx;
	}

	.rules-content {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 25rpx;
	}

	.border {
		position: absolute;
		right: -30rpx;
		top: 10rpx;
		width: 5rpx;
		height: 160rpx;
		background-color: #eee;
	}

	.bottom-left {
		width: 46%;
		position: relative;
	}

	.bottom-item {
		text-align: center;
		// display: flex;
		// justify-content: space-between;
		// align-content: center;
		padding-bottom: 15rpx;
	}

	.syAmt {
		color: #5597DA !important;
	}

	.bottom-number {
		font-weight: 600;
	}
</style>